home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / e / kyz_obj.lha / test / patchtest.e < prev    next >
Text File  |  1998-09-27  |  2KB  |  98 lines

  1. -> A little patch that reverses the text in the gadgets of requesters.
  2.  
  3. OPT OSVERSION=37,PREPROCESS
  4.  
  5. MODULE 'dos/dos',  'exec/memory', 'exec/semaphores',
  6.        'intuition/intuition', '*patch'
  7.  
  8. #define REQ(x,y) EasyRequestArgs(NIL, [20, 0, 'patchtest', x, y], 0, 0)
  9.  
  10. PROC main() HANDLE
  11.   DEF es=NIL:PTR TO patch
  12.  
  13.   -> install patch  (_LVOEasyRequestArgs = -588)
  14.   NEW es.install(intuitionbase, -588, {neweasy})
  15.  
  16.   -> and now enable our patch so it actually functions
  17.   es.enable()
  18.  
  19.   REQ('Requester choices now read backwards\nCtrl-C to exit', 'OK')
  20.  
  21.   Wait(SIGBREAKF_CTRL_C) -> wait for Ctrl-C
  22.  
  23.   es.disable()
  24.  
  25.   IF es.remove() = FALSE
  26.     -> if initial attempt to remove patch fails...
  27.     REQ('Program will quit when all requesters close.', 'Including this one')
  28.   ENDIF
  29.  
  30. EXCEPT DO
  31.   END es -> remove and uninstall patch
  32. ENDPROC
  33.  
  34.  
  35. -> the actual patch. This will be called from any process
  36. -> or task that thinks it's calling EasyRequestArgs()
  37.  
  38. -> (apologies for the 'branching out' and using highly unoptimised code -
  39. -> real world patches should be conservative with variables and calls to
  40. -> minimise stack usage)
  41.  
  42. #define REGISTERS a7, a6, a5, a4, a3, a2, a1:PTR TO easystruct, a0, \
  43.                   d7, d6, d5, d4, d3, d2, d1, d0
  44.  
  45. -> EasyRequestArgs(window,easyStruct,idcmpPtr,args)(a0/a1/a2/a3)
  46.  
  47. PROC neweasy(entry, REGISTERS)
  48.   DEF resp:REG
  49.  
  50.   resp := a1.gadgetformat
  51.  
  52.   -> reverse the string in the responses field.
  53.   reverse(resp)
  54.  
  55.   -> setup args for original function
  56.   MOVE.L a0, A0
  57.   MOVE.L a1, A1
  58.   MOVE.L a2, A2
  59.   MOVE.L a3, A3
  60.   MOVE.L a6, A6
  61.  
  62.   -> call original function
  63.   MOVE.L A4, -(A7)
  64.   MOVE.L entry, A4
  65.   JSR     (A4)
  66.   MOVE.L (A7)+, A4
  67.  
  68.   -> collect result
  69.   MOVE.L D0, d0
  70.  
  71.   -> reverse the string back again
  72.   reverse(resp)
  73.  
  74.   -> reverse the user's choice to match the real gadget
  75. ENDPROC IF d0 = 1 THEN 0 ELSE IF d0 = 0 THEN 1 ELSE bars(resp) + 2 - d0
  76.  
  77.  
  78. PROC reverse(str)
  79.   -> reverses the text in a normal string
  80.   DEF end:REG, len:REG, pos:REG, swap:REG
  81.  
  82.   len := StrLen(str)
  83.   end := str + len - 1
  84.  
  85.   FOR pos := 0 TO (len-1)/2
  86.     swap      := str[pos]
  87.     str[pos]  := end[-pos]
  88.     end[-pos] := swap
  89.   ENDFOR
  90. ENDPROC
  91.  
  92.  
  93. PROC bars(str)
  94.   -> returns a count of '|' symbols in a string
  95.   DEF count=0:REG, pos:REG
  96.   FOR pos := 0 TO StrLen(str) DO IF str[pos] = "|" THEN INC count
  97. ENDPROC count
  98.